package com.hz.springboot01.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;

import java.io.Serializable;

@Data
@AllArgsConstructor
@ToString
public class ResultJSON<T> implements Serializable {

    private Integer code;// 1  0
    private String msg;// 请求失败   请求成功
    private Long count; //
    private T data; //数据 list<对象> 单个对象   受影响行数

    public ResultJSON(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static com.hz.springboot01.util.ResultJSON successLayui(Long count, Object data){
        return  new com.hz.springboot01.util.ResultJSON(0,"操作成功",count,data);
    }

    public static com.hz.springboot01.util.ResultJSON successOrError(boolean bool){
        if(bool){
            return  com.hz.springboot01.util.ResultJSON.success();
        }else{
            return  com.hz.springboot01.util.ResultJSON.error();
        }

    }
    public static com.hz.springboot01.util.ResultJSON successOrError01(int bool){
        if(bool>0){
            return  com.hz.springboot01.util.ResultJSON.success();
        }else{
            return  com.hz.springboot01.util.ResultJSON.error();
        }

    }
    public static com.hz.springboot01.util.ResultJSON success(){
        return  new com.hz.springboot01.util.ResultJSON(0,"操作成功",null);
    }

    public static <R> com.hz.springboot01.util.ResultJSON success(R data){

        return  new com.hz.springboot01.util.ResultJSON(0,"操作成功",data);
    }

    public static com.hz.springboot01.util.ResultJSON error(){
        return  new com.hz.springboot01.util.ResultJSON(1,"操作失败",null);
    }


    public static com.hz.springboot01.util.ResultJSON error(Integer code, String msg){
        return  new com.hz.springboot01.util.ResultJSON(code,msg,null);
    }

    public static com.hz.springboot01.util.ResultJSON error(String msg){
        return  new com.hz.springboot01.util.ResultJSON(1,msg,null);
    }
}
